﻿
var sumBathAmount = null;
var sumBathAmountVat = null;
var sumBathAmountTax = null;
var tempSumBathAmount = 0.0;
var tempSumBathAmountVat = 0.0;
var tempSumBathAmountTax = 0.0;

function MRD_FooterLoadSumBathAmount(sender, args)
{
    sumBathAmount = sender;
}

function MRD_FooterLoadSumVatAmount(sender, args)
{
    sumBathAmountVat = sender;
}

function MRD_FooterLoadSumTaxAmount(sender, args)
{
    sumBathAmountTax = sender;
}

function txtBlur(tAmount, tExchangeRate, tBathAmount)
{
    var txtAmount = $find(tAmount);
    var txtExchangeRate = $find(tExchangeRate);
    var txtBathAmount = $find(tBathAmount);

    var dAmount = 0;
    var dExchangeRate = 0;
    var dBathAmount = 0;
    
    if (txtAmount.get_value().toString().length > 0)
        dAmount = txtAmount.get_value();
        
    if (txtExchangeRate.get_value().toString().length > 0)
        dExchangeRate = txtExchangeRate.get_value();
    
    dBathAmount = dAmount * dExchangeRate;
    txtBathAmount.set_value(dBathAmount);
    sumBathAmount.set_value(tempSumBathAmount + dBathAmount);
}

function txtFocus(tAmount, tExchangeRate, tBathAmount)
{
    var txtBathAmount = $find(tBathAmount);
    var dBathAmount = 0;
    
    if (txtBathAmount.get_value().toString().length > 0)
        dBathAmount = txtBathAmount.get_value();
        
    tempSumBathAmount = sumBathAmount.get_value() - dBathAmount;
}

function txtVatBlur(tAmount)
{
    var txtAmount = $find(tAmount);
    var dAmount = 0;
    
    if (txtAmount.get_value().toString().length > 0)
        dAmount = txtAmount.get_value();
    
    sumBathAmountVat.set_value(tempSumBathAmountVat + dAmount);
}

function txtVatFocus(tAmount)
{
    var txtAmount = $find(tAmount);
    var dAmount = 0;
    
    if (txtAmount.get_value().toString().length > 0)
        dAmount = txtAmount.get_value();
        
    tempSumBathAmountVat = sumBathAmountVat.get_value() - dAmount;
}

function txtTaxBlur(tAmount)
{
    var txtAmount = $find(tAmount);
    var dAmount = 0;
    
    if (txtAmount.get_value().toString().length > 0)
        dAmount = txtAmount.get_value();
    
    sumBathAmountTax.set_value(tempSumBathAmountTax + dAmount);
}

function txtTaxFocus(tAmount)
{
    var txtAmount = $find(tAmount);
    var dAmount = 0;
    
    if (txtAmount.get_value().toString().length > 0)
        dAmount = txtAmount.get_value();
        
    tempSumBathAmountTax = sumBathAmountTax.get_value() - dAmount;
}

function openWinExpRate(BgmSourceSeq, seq, tAmount, tExchangeRate, tBathAmount)
{                
    txtFocus(tAmount, tExchangeRate, tBathAmount);
    var oWndExpRate = radopen("FIM_ExpenseRates.aspx"
        + "?BgmSourceSeq=[0]&Seq=[1]&txtAmount=[2]&txtExchangeRate=[3]&txtBathAmount=[4]&txGrpAmount=[5]"
        .replace('[0]', BgmSourceSeq)
        .replace('[1]', seq)
        .replace('[2]', tAmount)
        .replace('[3]', tExchangeRate)
        .replace('[4]', tBathAmount)
        .replace('[5]', '')
        , "RadWindow2");
}
function openWinExpRateEmp(BgmSourceSeq, seq, tAmount, tExchangeRate, tBathAmount)
{                
    txtFocus(tAmount, tExchangeRate, tBathAmount);
    var oWndExpRate = radopen("FIM_ExpenseRateEmps.aspx"
        + "?BgmSourceSeq=[0]&Seq=[1]&txtAmount=[2]&txtExchangeRate=[3]&txtBathAmount=[4]&txGrpAmount=[5]"
        .replace('[0]', BgmSourceSeq)
        .replace('[1]', seq)
        .replace('[2]', tAmount)
        .replace('[3]', tExchangeRate)
        .replace('[4]', tBathAmount)
        .replace('[5]', '')
        , "RadWindow2");
}
function OnClientCloseExpRate(oWndExpRate,argsExpRate)
{
    //get the transferred arguments
    
    var argExpRate = argsExpRate.get_argument();
    if(argExpRate)
    {
        var txtBathAmount = $find(argExpRate.tAmount);
        txtBathAmount.set_value(argExpRate.amount);
        txtBlur(argExpRate.tAmount, argExpRate.tExchangeRate, argExpRate.tBathAmount, argExpRate.tGrpAmount);
    }
}